﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using OrderingPlatform.BllService.CommonManage;
using OrderingPlatform.MvcExtension;

namespace OrderingPlatform.WebUI.Controllers
{
    public class FileManagerController : Controller
    {
        //
        // GET: /FileManager/

        [OutputCache(Duration = 60 * 10, VaryByParam = "fileId")]
        public ActionResult Image(Guid fileId)
        {
            try
            {
                var fileService = new FileService();
                var image = fileService.GetFileStream(fileId);
                return new ImageResult(image.Image);
            }
            catch
            {
                return new ImageResult(null);
            }
        }

        [OutputCache(Duration = 60 * 10, VaryByParam = "fileId")]
        public ActionResult Thumbnail(Guid fileId)
        {
            try
            {
                var fileService = new FileService();
                var image = fileService.GetFileStream(fileId, true);
                return new ImageResult(image.Image);
            }
            catch
            {
                return new ImageResult(null);
            }

        }
        [OutputCache(Duration = 60 * 10, VaryByParam = "fileId")]
        public ActionResult Middlenail(Guid fileId)
        {
            try
            {
                var fileService = new FileService();
                var image = fileService.GetMiddleFileStream(fileId);
                return new ImageResult(image.Image);
            }
            catch
            {
                return new ImageResult(null);
            }
        }
        [OutputCache(Duration = 60 * 10, VaryByParam = "fileId")]
        public ActionResult Smallenail(Guid fileId)
        {
            try
            {
                var fileService = new FileService();
                var image = fileService.GetSmallFileStream(fileId);
                return new ImageResult(image.Image);
            }
            catch
            {
                return new ImageResult(null);
            }
        }

        public string UploadImage(HttpPostedFileBase Filedata, string directory)
        {
            var fileService = new FileService();
            var g = fileService.SaveFile(Filedata, directory);
            return g.ToString();
        }
    }
}
